package com.reserv.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.reserv.dao.ReservDAO;
import com.reserv.util.TimestampUtil;

public class CheckReservServlet extends HttpServlet {
	private ReservDAO dao;
	
	@Override
	public void init(ServletConfig config) throws ServletException {
		dao = ReservDAO.getInstance();
	}
	
	private void doProcess(HttpServletRequest request,
			HttpServletResponse response) throws ServletException,IOException {
		
		int sno = Integer.parseInt(request.getParameter("sno"));
		String year = request.getParameter("year");
		String month = request.getParameter("month");
		String date = request.getParameter("date");
		
		TimestampUtil tsu = new TimestampUtil();
		
	
		ArrayList<Integer> list = (ArrayList<Integer>) dao.getReservList(
				sno, tsu.toTimestamp(year + "-" + month + "-" + date));
		
		System.out.println(list);
		
		Gson gson = new Gson();
		
		String json = gson.toJson(list);
		
		PrintWriter out = response.getWriter();
		
		out.println(json);
	}
	protected void doGet(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		doProcess(request, response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		doProcess(request, response);
	}

}
